package com.sto.stoapp.activity.administrator;

import android.os.Bundle;
import android.view.View;

import com.sto.stoapp.activity.R;
import com.sto.stoapp.broadcast.HomeBroadAction;
import com.sto.stoapp.db.StoFilePreference;
import com.sto.stoapp.widget.StoHomeActivity;
import com.sto.stoapp.widget.StoSelectLinearLayout;

public class Switch24HourActivity extends StoHomeActivity {
    private StoSelectLinearLayout operatorControlLayout;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.switch24_hour_layout);
        this.setTitleBottom("24小时件开关",
                HomeBroadAction.ADMINISTRATOR_BROAD);
        initWidget();
        initListener();
    }

    private void initWidget(){
        operatorControlLayout = (StoSelectLinearLayout) findViewById(R.id.switchView);
        operatorControlLayout.setTitle(R.string.allow_24);
        operatorControlLayout.setSelectStatus(StoFilePreference.getInstance(
                this).get24Switch());
    }

    private void initListener(){
        operatorControlLayout.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (operatorControlLayout.getSelectStatus()) {
                    operatorControlLayout.setSelectStatus(false);
                } else {
                    operatorControlLayout.setSelectStatus(true);
                }
                StoFilePreference.getInstance(Switch24HourActivity.this)
                        .set24Switch(operatorControlLayout.getSelectStatus());
            }
        });
    }
}
